import type { TAddressParams, TAddressResult } from '@/types/address'
import type { TPageParams } from '@/types/global'
import type { TLoginResult, TPersonProfile, TUpdateProfileParams } from '@/types/login'
import { http } from '@/utils/http'

class LoginApi {
  /**
   * @returns 模拟微信小程序一键登录
   * @params phoneNumber 手机号码
   */
  public static getSimpleLogin(phoneNumber: string) {
    return http<TLoginResult>({
      url: '/login/wxMin/simple',
      method: 'POST',
      data: {
        phoneNumber,
      },
    })
  }

  /**
   * @returns 获取个人详细信息
   */
  public static getPersonProfile() {
    return http<TPersonProfile>({ url: '/member/profile', method: 'GET' })
  }

  /**
   * @returns 修改个人信息
   */
  public static updatePersonProfile(data: TUpdateProfileParams) {
    return http<TPersonProfile>({
      url: '/member/profile',
      method: 'PUT',
      data,
    })
  }

  /**
   * @returns 新增地址
   * @params {TAddressParams} 地址信息参数
   */
  public static addAddress(data: TAddressParams) {
    return http<TAddressParams>({
      url: '/member/address',
      method: 'POST',
      data,
    })
  }

  /**
   * @returns 获取地址列表
   */
  public static getAddressList() {
    return http<TAddressResult[]>({
      url: '/member/address',
      method: 'GET',
    })
  }

  /**
   * @returns 获取地址详情
   * @params {id} 地址id
   */
  public static getAddressDetail(id: string) {
    return http<TAddressResult>({
      url: `/member/address/${id}`,
      method: 'GET',
    })
  }

  /**
   * @returns 修改地址
   * @params {id} 地址id
   */
  public static updateAddressById(id: string, data: TAddressParams) {
    return http<TAddressResult>({
      url: `/member/address/${id}`,
      method: 'PUT',
      data,
    })
  }
  /**
   * @returns 删除地址
   * @params {id}地址id
   */
  public static deleteAddress(id: string) {
    return http<{ id: string }>({
      url: `/member/address/${id}`,
      method: 'DELETE',
    })
  }
}

export default LoginApi
